Skip to content

SGPINF-961: fix: add litellm retry with exponential backoff for rate limit errors#257

Merged
sayakmaity merged 1 commit intomainfrom
fix/add-litellm-retry-policy
Feb 6, 2026
Merged

SGPINF-961: fix: add litellm retry with exponential backoff for rate limit errors#257
sayakmaity merged 1 commit intomainfrom
fix/add-litellm-retry-policy

Conversation

@sayakmaity
Copy link
Contributor

Summary

  • Add num_retries=3 default to LLMConfig so litellm automatically retries OpenAI 429 rate limit errors with built-in exponential backoff
  • Increase Temporal DEFAULT_RETRY_POLICY from maximum_attempts=1 (zero retries) to maximum_attempts=3 with exponential backoff (1s → 2s → 4s, max 30s)

Context

Under high concurrent load (500 users × 40 messages), agent pods forward all requests to OpenAI simultaneously with no retry logic. When OpenAI rate limits kick in (429), the SDK immediately surfaces ServiceUnavailableError with no retry attempt.

This PR is the SDK-side companion to scaleapi/scale-agentex#144, which reduces HTTPX connection pool limits in the agentex backend to add backpressure.

Together these two PRs:

  1. Backend — throttles how many concurrent requests reach agent pods (200 vs 1000)
  2. SDK (this PR) — retries gracefully when OpenAI does return 429s

Test plan

  • pytest tests/ passes (141 passed, 2 skipped)
  • Deploy to dev with updated SDK, confirm retries work under load
  • Load test: verify ServiceUnavailableError count drops significantly

- Add `num_retries=3` default to LLMConfig so litellm retries on OpenAI
  429 rate limit errors with built-in exponential backoff
- Increase Temporal DEFAULT_RETRY_POLICY from 1 attempt (no retries) to
  3 attempts with exponential backoff (1s, 2s, 4s... up to 30s)

This complements the HTTPX connection limit reduction in agentex backend
(scaleapi/scale-agentex#144) to address OpenAI rate limiting under high
concurrent load.
@sayakmaity sayakmaity requested a review from smoreinis February 5, 2026 20:53
@sayakmaity sayakmaity merged commit 04f6f8b into main Feb 6, 2026
29 checks passed
@sayakmaity sayakmaity deleted the fix/add-litellm-retry-policy branch February 6, 2026 00:34
@sayakmaity sayakmaity changed the title fix: add litellm retry with exponential backoff for rate limit errors SGPINF-961: fix: add litellm retry with exponential backoff for rate limit errors Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants